<?php
include($folder.'/layouts/code-behind/backend.php');
function blc_naplo_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	return
		query(
			'SELECT
				l.request AS request,
				l.referer AS referer,
				l.id AS id, 
				l.host AS host, 
				l.address AS address, 
				DATE_FORMAT(l.created,\'%Y.%m.%d. %H:%i:%s\') AS created 
			FROM log l
			ORDER BY  
				CASE WHEN :orderBy = \'host_asc\' THEN host END ASC,
				CASE WHEN :orderBy = \'host_desc\' THEN host END DESC,
				CASE WHEN :orderBy = \'address_asc\' THEN address END ASC,
				CASE WHEN :orderBy = \'address_desc\' THEN address END DESC,
				CASE WHEN :orderBy = \'created_asc\' THEN created END ASC,
				CASE WHEN :orderBy = \'created_desc\' THEN created END DESC,
				CASE WHEN :orderBy = \'request_asc\' THEN request END ASC,
				CASE WHEN :orderBy = \'request_desc\' THEN request END DESC,
				CASE WHEN :orderBy = \'referer_asc\' THEN referer END ASC,
				CASE WHEN :orderBy = \'referer_desc\' THEN referer END DESC
			LIMIT :from,:itemsPerPage',
			array('orderBy'=>$orderBy, 'from'=>$from, 'itemsPerPage'=>$itemsPerPage));
}
function blc_naplo_select_count()
{
	return queryScalar('SELECT COUNT(1) FROM log l', null);
}
function blc_login_try_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	return
		query(
			'SELECT
				lt.`id`,
				lt.`address`,
				lt.`host`,
				lt.`password`,
				DATE_FORMAT(lt.`datetime`,\'%Y.%m.%d. %H:%i:%s\') AS `datetime`
			FROM login_try lt
			ORDER BY 
				CASE WHEN :orderBy = \'host_asc\' THEN `host` END ASC,
				CASE WHEN :orderBy = \'host_desc\' THEN `host` END DESC,
				CASE WHEN :orderBy = \'address_asc\' THEN `address` END ASC,
				CASE WHEN :orderBy = \'address_desc\' THEN `address` END DESC,
				CASE WHEN :orderBy = \'password_asc\' THEN `password` END ASC,
				CASE WHEN :orderBy = \'password_desc\' THEN `password` END DESC,
				CASE WHEN :orderBy = \'datetime_asc\' THEN `datetime` END ASC,
				CASE WHEN :orderBy = \'datetime_desc\' THEN `datetime` END DESC
			LIMIT :from,:itemsPerPage',
			array('orderBy'=>$orderBy,'from'=>$from, 'itemsPerPage'=>$itemsPerPage));
}
function blc_login_try_select_count()
{
	return queryScalar('SELECT COUNT(1) FROM login_try lt', null);
}
$master['action'] = null;
$master['attributes'] = null;
$master['pageTitle'] = 'Napló';
?>